//package com.example.springai.controller;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.ai.openai.OpenAiAudioSpeechModel;
//import org.springframework.ai.openai.OpenAiAudioSpeechOptions;
//import org.springframework.ai.openai.api.OpenAiAudioApi;
//import org.springframework.ai.openai.audio.speech.SpeechPrompt;
//import org.springframework.ai.openai.audio.speech.SpeechResponse;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.FileOutputStream;
//
//@RestController
//@Slf4j
//public class OpenaiController {
//
//    @Autowired
//    private OpenAiAudioSpeechModel openAiAudioSpeechModel;
//
//    @GetMapping(value = "/openai/generateAudio")
//    public void generateAudio(@RequestParam(value = "message", defaultValue = "我是一只可爱的小花猫") String message) {
//        SpeechResponse response = openAiAudioSpeechModel.call(new SpeechPrompt(message, OpenAiAudioSpeechOptions.builder()
//                .withSpeed(1.0f)
//                .withResponseFormat(OpenAiAudioApi.SpeechRequest.AudioResponseFormat.MP3)
//                .withVoice(OpenAiAudioApi.SpeechRequest.Voice.NOVA).build()));
//        //将byte数组转换为mp3文件保存
//        convertBytesToMp3(response.getResult().getOutput());
//
//    }
//
//    public static void convertBytesToMp3(byte[] audio) {
//        try {
//            // 将字节数组转换成语音文件并保存到本地
//            FileOutputStream fos = new FileOutputStream("C:\\Users\\18716\\Pictures\\output.mp3");
//            fos.write(audio);
//            fos.close();
//        } catch (Exception e) {
//            log.error("语音转换异常：", e);
//        }
//    }
//
//}
